Regular COM components are great when you're working with single blocks of data held in memory—for example, all the information you have about a customer. But COM components are awkward to work with when your data is to be read from and written to a database. Yes, you can implement a persistence mechanism based on custom Load and Save methods (or based on the new persistable classes in Microsoft Visual Basic 6), but this means a lot of additional work for the author of the component and for the programmer who uses it.
Visual Basic 6 offers a novel solution to this problem, based on new binding capabilities in ADO. In this chapter, I show you how to create data source classes that read data from a database. I also show you how to create consumer classes that bind themselves to data sources to retrieve data and automatically receive notifications when another record becomes current. You can then turn these classes into COM components so that you can reuse them more easily. I also illustrate how to create a custom version of the ADO Data control, a feat that wasn't possible in Visual Basic 5 (whose binding capabilities permitted you to create data consumer controls only, not data sources). All the data-aware classes you create can be used exactly as data-aware objects provided by Visual Basic itself, such as the DataEnvironment designer and the ADO Data control.